#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node *next;
};

void insert(struct Node **head, int data) {
    struct Node *newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = NULL;

    if (*head == NULL) {
        *head = newNode;
        return;
    }

    struct Node *current = *head;
    while (current->next != NULL) {
        current = current->next;
    }
    current->next = newNode;
}

void release(struct Node **head) {
    struct Node *current = *head;
    while (current != NULL) {
        struct Node *temp = current;
        current = current->next;
        free(temp);
    }
}

void mergeLists(struct Node **LA, struct Node *LB) {
    struct Node dummy;
    struct Node *tail = &dummy;
    dummy.next = NULL;

    struct Node *currentA = *LA;
    struct Node *currentB = LB;

    while (currentA != NULL && currentB != NULL) {
        if (currentA->data < currentB->data) {
            tail->next = currentA;
            currentA = currentA->next;
        } else if (currentA->data > currentB->data) {
            tail->next = currentB;
            currentB = currentB->next;
        } else {
            tail->next = currentA;
            currentA = currentA->next;
            currentB = currentB->next;
        }
        tail = tail->next;
        tail->next = NULL;
    }

    if (currentA != NULL) {
        tail->next = currentA;
    }

    if (currentB != NULL) {
        tail->next = currentB;
    }

    *LA = dummy.next;
}

void printList(struct Node *head) {
    struct Node *current = head;
    while (current != NULL) {
        printf("%d ", current->data);
        current = current->next;
    }
    printf("\n");
}

int main() {
    int m, n;

    scanf("%d", &m);
    struct Node *LA = NULL;

    for (int i = 0; i < m; i++) {
        int value;
        scanf("%d", &value);
        insert(&LA, value);
    }


    scanf("%d", &n);
    struct Node *LB = NULL;

    for (int i = 0; i < n; i++) {
        int value;
        scanf("%d", &value);
        insert(&LB, value);
    }

    mergeLists(&LA, LB);


    printList(LA);

    release(&LA);
    return 0;
}
